package com.hone.honewed.service.qcloudsms.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.eig.common.entity.system.TbMember;
import com.eig.common.vo.Result;
import com.hone.honewed.dao.qcloudsms.QcloudsmsDao;
import com.hone.honewed.uilt.Sendmss;
import com.hone.honewed.service.qcloudsms.QcloudsmsService;
import com.hone.honewed.uilt.mmm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.Random;

/**
 * @author ：YQ袁（2446806940@qq.com）
 * @date ：Created in 2023/1/9 16:57
 * @description：
 * @modified By：
 * @version:
 */
@Service
public class QcloudsmsServiceImpl extends Sendmss implements QcloudsmsService {
    @Autowired
    private QcloudsmsDao qcloudsmsDao;
    @Override
    public Result getYanZhengMa(String member) {
        Random random = new Random();
        String result="";
        for (int i=0;i<6;i++)
        {
            result+=random.nextInt(10);
        }

        try {
            sendSms(member,result);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return new Result(2000,"发送成功",result);
    }

    @Override
    public Result updateMemberPassword(String member, String newPassword) {
        Map<String, String> stringStringMap = mmm.makePasswordSalt(newPassword);
        String password = stringStringMap.get("password");
        String salt = stringStringMap.get("salt");

        UpdateWrapper<TbMember> wrapper = new UpdateWrapper<>();
        wrapper.set("password",password);
        wrapper.set("salt",salt);
        wrapper.eq("mobile",member);
        int update = qcloudsmsDao.update(null, wrapper);
        if (update>0){
            return new Result(2000,"密码修改成功");
        }
        return new Result(5000, "密码修改失败");
    }

}
